//
//  movieCommentTableViewCell.m
//  HuiWenMovie
//
//  Created by niceDay on 15/7/27.
//  Copyright (c) 2015年 computer. All rights reserved.
//

#import "movieCommentTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "UIViewExt.h"
#import "common.h"
@implementation movieCommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self _createContentView];
       // self.selectionStyle = UITableViewCellEditingStyleNone;
    }
    return self;
}

- (void)_createContentView{
    _bgImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    _userImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    _nicknameLable = [[UILabel alloc] initWithFrame:CGRectZero];
    _ratingLable = [[UILabel alloc] initWithFrame:CGRectZero];
    _commentLable = [[UILabel alloc] initWithFrame:CGRectZero];
    _nicknameLable.font = [UIFont systemFontOfSize:18];
    _nicknameLable.numberOfLines = 0;
 //   _nicknameLable.textColor = [UIColor blackColor];
    
    [self.contentView addSubview:_userImageView];
    [self.contentView addSubview:_bgImageView];
    [self.contentView addSubview:_nicknameLable];
    [self.contentView addSubview:_ratingLable];
    [self.contentView addSubview:_commentLable];
    
}



- (void)setModal:(tableModal *)modal{
    _modal = modal;
    [self setNeedsLayout];
}

- (void)setIsSpread:(BOOL)isSpread{
    _isSpread = isSpread;
    [self setNeedsLayout];
}

- (void)setContenSize:(CGSize)contenSize{
    _contenSize = contenSize;
    [self setNeedsLayout];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.backgroundColor = [UIColor blackColor];
    [_userImageView sd_setImageWithURL:[NSURL URLWithString:_modal.userImage]];
    _userImageView.frame = CGRectMake(5, 15, 50, 60);
    _nicknameLable.frame = CGRectMake(65, 20, 150, 20);
    _ratingLable.frame = CGRectMake(Kwidth - 80, 20, 40, 20);
    UIImage *bgImage = [UIImage imageNamed:@"movieDetail_comments_frame"];
    bgImage = [bgImage stretchableImageWithLeftCapWidth:bgImage.size.width*0.5 topCapHeight:bgImage.size.height*0.7];
      _bgImageView.image = bgImage;

   // _bgImageView.backgroundColor = [UIColor redColor];
    
    _commentLable.font = [UIFont systemFontOfSize:16];
    if (_isSpread == YES) {

        _bgImageView.frame = CGRectMake(45, 15, Kwidth-60, 70+_contenSize.height);

        _commentLable.frame = CGRectMake(65, 50,Kwidth-80, _contenSize.height);
         _commentLable.numberOfLines = 0;
        [_commentLable sizeToFit];
        
    }
    else{
        _commentLable.frame = CGRectMake(65, 50, Kwidth-80, 20);
        _bgImageView.frame = CGRectMake(45, 15, Kwidth-60, 75);
   
       _commentLable.numberOfLines = 1;
    }
   
    
    
    _commentLable.text = _modal.content;
    _commentLable.textAlignment = NSTextAlignmentLeft;
   
    _nicknameLable.text = _modal.nickname;

    _ratingLable.text = _modal.rating;
    
}


//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
//
//    // Configure the view for the selected state
//}

@end
